const pkg = require('../package');
const path = require('path');

function resolve(dir) {
    return path.join(__dirname, '..', dir);
}
const isDev = process.env.NODE_ENV !== 'production';

const router = require(resolve('nuxt/router/index.js'));

module.exports = {
    mode: 'universal',

    srcDir: resolve('nuxt'),
    buildDir: isDev ? '.nuxt' : resolve('app/public/nuxt-dist'),
    rootDir: resolve(''),
    /*
      ** Headers of the page
      */
    head: {
        title: pkg.name,
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: pkg.description },
        ],
        link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
    },

    /*
      ** Customize the progress-bar color
      */
    loading: { color: '#f00' },

    /*
      ** Global CSS
      */
    css: ['~/assets/style/app.scss'],

    /*
      ** Plugins to load before mounting the App
      */
    plugins: ['~/plugins/axios/index.js', '~/plugins/inject.js', '~/plugins/components.js'],

    /*
      ** Nuxt.js modules
      */
    modules: [
        // Doc: https://github.com/nuxt-community/axios-module#usage
        '@nuxtjs/axios',
    ],
    /*
      ** Axios module configuration
      */
    axios: {
        // See https://github.com/nuxt-community/axios-module#options
        host: pkg.server.host,
        port: pkg.server.port,
        proxy: true,
    },

    proxy: {
        '/rpc/': 'http://192.168.1.152:7905',
        // '/rpc/': 'http://b2b.signedexpress.com',
    },

    router: {
        linkActiveClass: 'active',
        linkExactActiveClass: 'exact-active',
        // middleware: 'appData', // 获取 app 公用数据的中间件
    },

    /*
      ** Build configuration
      */
    build: {
        /*
        ** You can extend webpack config here
        */
        extend(
            config,
            {
                loaders: { scss },
            },
        ) {
            scss.data = `@import "~/assets/style/_index.scss";`;
        },
        // 创建路由, 不用 nuxt 默认的根据pages目录创建路由配置的方法
        createRoutes: router,
    },
};
